package com.info33.platform.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.info33.platform.common.enums.StatusEnum;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.doc.entity.DocFileDetail;
import com.info33.platform.doc.service.DocFileService;
import com.info33.platform.system.dao.SysConfigImgDao;
import com.info33.platform.system.entity.SysConfigImg;
import com.info33.platform.system.service.SysConfigImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author admin
 */
@Service
public class SysConfigImgServiceImpl extends ServiceImpl<SysConfigImgDao, SysConfigImg> implements SysConfigImgService {

    @Autowired
    private DocFileService docFileService;

    @Override
    public Result<List<DocFileDetail>> upload(MultipartFile[] multipartFiles, String type, Long tid) {
        Result<List<DocFileDetail>> result = docFileService.businessUpload(multipartFiles, "system", tid);
        if (StatusEnum.SUCCESS.getCode() != result.getCode()) {
            return Result.error(result.getMessage());
        }
        SysConfigImg entity = new SysConfigImg();
        entity.setType(type);
        entity.setPath(result.getData().get(0).getNewName());
        if (Boolean.TRUE.equals(this.save(entity))) {
            return Result.ok(result.getData());
        }
        return Result.error();
    }
}